package com.cfec.ipoth_service.Config;

import com.cfec.ipoth_service.util.TokenUtil;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MyInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        String token = request.getHeader("token");
//        测试请求放行
        if("OPTIONS".equals(request.getMethod())){
            return true;
        }
        if(token != null&&!"".equals(token)){

            boolean bool = new TokenUtil().verifyToken(token);
            if(bool){

                return true;
            }else{

                response.getWriter().println("token过期");
                return false;
            }
        }else{

            response.getWriter().println("无token");
            return false;
        }




    }

}